package org.scohen.juploadr.uploadapi.abilities;

import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.scohen.juploadr.app.geo.GeoLocation;
import org.scohen.juploadr.util.NonNullList;
import org.scohen.juploadr.util.Persister;

public class GeoAbilities implements AbilitiesList {
    private Map<String,GeoLocation> locations = new HashMap<String, GeoLocation>();
    private Persister<GeoLocation> gp;
    private String[] accuracies = {"accuracy.none",
            "accuracy.world","accuracy.world",
            "accuracy.country","accuracy.country","accuracy.country",
            "accuracy.region","accuracy.region","accuracy.region","accuracy.region","accuracy.region",
            "accuracy.city","accuracy.city","accuracy.city","accuracy.city","accuracy.city",
            "accuracy.street"};
    
    public GeoAbilities() {
        gp = (Persister<GeoLocation>) Persister.getInstance(GeoLocation.class);
        for(GeoLocation g : gp.loadAll()) {
            if( g != null) {
                locations.put(g.getName(), g);
            }
        }
    }

    public Map<String,GeoLocation> getLocations() {
        return locations;
    }

    public void removeLocation(GeoLocation toRemove) {
        locations.remove(toRemove);
        gp.remove(toRemove);
    }
    
    public void addLocation(GeoLocation toAdd) {
        if (!locations.containsValue(toAdd)) {
            locations.put(toAdd.getName(),toAdd);
        }
        gp.persist(toAdd);
    }

    public boolean allDisabled() {
        return false;
    }

    public void notified(AbilityNotification n) {
    }

    public boolean hasPrivacy() {
        return true;
    }

    public boolean hasFriendsPrivacy() {
        return true;
    }

    public boolean hasContactsPrivacy() {
        return true;
    }

    public boolean hasFamilyPrivacy() {
        return true;
    }

    public boolean hasGeoAbilities() {
        return true;
    }

    public boolean hasAccuracy() {
        return true;
    }

    public int getMinAccuracy() {
        return 1;
    }

    public int getMaxAccuracy() {
        return 16;
    }
    
    public String[] getAccuracyLabels() {
        return accuracies;
    }

}
